import { EmployeeData, EmployeeResult, LoginResult } from "@/types/employee";
import request from "@/utils/request";

interface loginData {
  username: string
  password: string
}

/**
 * 登录
 * @param data body参数
 * @returns 
 */
export const postEmployeeLoginAPI = (params: loginData) => {
  return request<LoginResult>({
    method: 'POST',
    url: '/business/login',
    data: params
  })
}
/**
 * 退出
 * @returns 
 */
export const postEmployeeLogoutAPI = () => {
  return request({
    method: 'POST',
    url: '/business/logout'
  })
}
/**
 * 根据id查询商家
 * @param id 
 * @returns 
 */
export const getBusinessAPI = (id: number) => {
  return request<EmployeeResult>({
    method: 'GET',
    url: `/business/${id}`
  })
}
/**
 * 编辑员工信息 Body参数
 * @param params
 * @returns
 */
export const putBusinessAPI = (params: EmployeeData) => {
  return request({
    method: 'PUT',
    url: '/business',
    data: params
  })
}
// 修改头像
export const putBusinessAvatarAPI = (id: number, avatar: string) => {
  return request({
    method: 'PUT',
    url: '/business/avatar',
    params: { id, avatar }
  })
}
/**
 * 修改密码
 */
interface pwdData {
  id: number
  oldPassword: string
  newPassword: string
}
export const putBusinessPwdAPI = (params: pwdData) => {
  return request({
    method: 'PUT',
    url: '/business/editPassword',
    data: params
  })
}